home *** CD-ROM | disk | FTP | other *** search
- /* Screen Saver Clock.
- -------------------
-
- Roger Dalton of R&D Associates.
-
- */
-
-
- #include <stdio.h>
- #include <stdlib.h>
-
- #include "tsrlib.h"
-
-
- /* Table must exist! */
-
- HOTKEY hotkey_table[] = {
- LAST_KEY /* no hotkeys needed */
- };
-
-
- /* Signature must exist! */
-
- char signature[] = "SCREEN SAVER";
-
-
- /* Structure to hold DOS time. */
-
- typedef struct {
- int hour;
- int min;
- int sec;
- int hsec;
- } TIMES;
-
-
- /* Specify only what you need. If you won't need a heap, specify a
- small value like this as 0 means 'use all possible'. NOTE: Turbo C2.0
- user can't specify less than about 512 anyway! */
-
- unsigned int _heaplen = 512;
- unsigned int _stklen = 256;
-
-
- volatile int screen_state = 1; /* screen is visible */
- unsigned int far *screen; /* pointer to video screen */
- int screen_timer = 0; /* delay timer 1/2 seconds */
-
- char screen_save[8000]; /* screen save buffer */
-
-
- /* PROTOTYPES */
-
- void get_time(TIMES *timerp);
- int get_mode(void);
- int my_key_handler(int scancode, int shiftmask);
-
-
-
- /* The main program. The only possibilites are:
-
- saver interval
- or
- saver interval foreground
- or
- saver interval foreground background
- */
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- TIMES tim; /* time structure */
- int mode; /* video mode */
- unsigned int chr; /* buffer for characters */
- unsigned int attr = 0x7000; /* screen sttribute */
- unsigned int far *scp; /* temp pointer to video screen */
- int i; /* loop counter */
- int flip = 0; /* colon ticker */
- char tmp[32]; /* time string buffer */
- static char tick[] = ": ";
- int old_sec = 0;
- int screen_limit; /* delay before saving */
-
- if (resident_tsr()) {
- printf("%s is already resident.\n", signature);
- exit(1);
- }
- printf("%s is loaded.\n", signature);
-
- keypressed = my_key_handler;
-
- if (argc > 1) {
- screen_limit = atoi(argv[1]) << 1;
- } else {
- screen_limit = 60 * 2;
- }
-
- if (argc > 2) {
- attr &= 0xf000;
- attr |= atoi(argv[2]) << 8;
- }
-
- if (argc > 3) {
- attr &= 0x0f00;
- attr |= atoi(argv[3]) << 12;
- }
-
- screen = (unsigned int far *)((get_mode() == 7)? 0xb0000000L: 0xb8000000L);
-
- /* Past here CAN'T use printf etc. */
-
- go_tsr(SLEEP, 1);
-
- while (1) {
- mode = get_mode();
- if (mode == 7 || mode == 3 || mode == 2) {
-
- if (screen_state) {
-
- if (screen_timer++ > screen_limit) {
- movedata(FP_SEG(screen), 0, _DS, (unsigned)screen_save, 8000);
- for (i = 8000, scp = screen; i-- > 0;) {
- *scp++ = 0x0720;
- }
- screen_state = 0;
- goto sleep;
- }
-
- if (mode == 7) {
- attr = 0x7000;
- }
-
- get_time(&tim);
- if (tim.sec != old_sec) {
- flip ^= 1; /* flip the colon */
- }
- old_sec = tim.sec;
- sprintf(tmp, " %02d%c%02d%c%02d ", tim.hour, tick[flip],
- tim.min, tick[!flip], tim.sec);
-
- for (i = 0; (chr = tmp[i]); i++) {
- screen[35 + i] = chr | attr;
- }
- }
- }
- sleep:
- suspend_tsr(SLEEP, 9);
- }
- }
-
-
-
-
- /* Function to read DOS date & time, and build the structure. */
-
- void get_time(TIMES *timerp)
- {
- union REGS regs;
-
- regs.h.ah = 0x2c;
- int86(0x21, ®s, ®s);
- timerp->hour = regs.h.ch;
- timerp->min = regs.h.cl;
- timerp->sec = regs.h.dh;
- timerp->hsec = regs.h.dl;
- }
-
-
-
-
- /* Return the current display mode. */
-
- int get_mode(void)
- {
- _AH = 0x0f;
- geninterrupt(0x10);
- return _AL;
- }
-
-
-
-
- /* Hendler for keypresses. Eats the key which lights up the screen. */
-
- int my_key_handler(int scancode, int shiftmask)
- {
- screen_timer = 0; /* clear on every key */
- if (screen_state) {
- return 0;
- } else {
- screen_state = 1;
- movedata(_DS, (unsigned)screen_save, FP_SEG(screen), 0, 8000);
- _TS_tic_count = _TS_bg_limit + 1; /* instant timeout! */
-
- /* don't eat non-typing keys */
-
- switch (scancode) {
-
- case 29: /* caps lock */
- case 42: /* left shift */
- case 56: /* ctrl */
- case 54: /* right shift */
- case 58: /* alt */
- return 0;
- }
- return EAT_KEY;
- }
- }
-